/*******************************************************************************
 * Package: com.hngtrust.iir.bond.controller
 * Type:    BondController
 * Date:    2021/12/14 9:38 上午
 *
 * Copyright (c) 2021 -------- -------- CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.bond.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hngtrust.framework.bind.ResponseInfo;
import com.hngtrust.framework.page.PageResult;
import com.hngtrust.framework.page.service.PageService;
import com.hngtrust.iir.bond.dto.*;
import com.hngtrust.iir.bond.service.BondBusService;
import com.hngtrust.iir.dto.ReqDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 债券信息
 *
 * @author Chaidd
 * @date 2021/12/14 9:38 上午
 */
@Slf4j
@Api(tags = "债券信息")
@RestController
@RequestMapping("/bond")
public class BondController {

    @Autowired
    private BondBusService bondBusService;

    /**
     * 分页服务
     */
    @Autowired
    private PageService pageService;

    @ApiOperation(value = "债券信息查询", notes = "债券信息查询")
    @PostMapping("/query-bond")
    public ResponseInfo<PageResult<BondRespVO>> queryBond(
            @ApiParam("债券信息请求参数") @Valid @RequestBody ReqDTO<BondReq> bondReq) throws JsonProcessingException {
        log.info("BondController.queryBond start...");
        return bondBusService.queryBond(bondReq);
    }

    @ApiOperation(value = "债券类型查询", notes = "债券类型查询")
    @PostMapping("/query-bondType")
    public ResponseInfo<List<BondTypeRespVO>> queryBondType() throws JsonProcessingException {
        log.info("BondController.queryBondType start...");
        return bondBusService.queryBondType();
    }

    @ApiOperation(value = "债券模板下载", notes = "债券模板下载")
    @PostMapping("/template-download")
    public ResponseInfo templateDownload(HttpServletResponse response) throws IOException {
        log.info("BondController.templateDownload start...");
        bondBusService.templateDownload(response);
        return new ResponseInfo();
    }

    @ApiOperation(value = "批量查询债券数据", notes = "批量查询债券数据")
    @PostMapping("/query-batchBond")
    public ResponseInfo<BondTmpRespVO> queryBatchBond(
            @ApiParam(value = "导入文件", type = "MultipartFile", required = true) @RequestParam() MultipartFile file)
            throws IOException {
        log.info("BondController.queryBatchBond start...");
        return bondBusService.queryBatchBond(file);
    }

    @ApiOperation(value = "债券数据导出", notes = "债券数据导出")
    @PostMapping("/data-export")
    public void dataExport(
            @ApiParam("债券请求参数") @Valid @RequestBody ReqDTO<BondReq> bondReq, HttpServletResponse response)
            throws IOException {
        log.info("BondController.dataExport start...");
        bondBusService.dataExport(bondReq,response);
    }

    @ApiOperation(value = "债券评级详情查询", notes = "债券评级详情查询")
    @PostMapping("/query-bondRating")
    public ResponseInfo<PageResult<BondRatingDetailRespVO>> queryBondRating(
            @ApiParam("债券评级详情请求参数") @Valid @RequestBody ReqDTO<BondDetailReq> bondDetailReq) throws JsonProcessingException {
        log.info("BondController.queryBondRating start...");

        return bondBusService.queryBondRating(bondDetailReq);
    }

    @ApiOperation(value = "债券信息详情查询", notes = "债券信息详情查询")
    @PostMapping("/query-bondDetail")
    public ResponseInfo<BondDetailRespVO> queryBondDetail(
            @ApiParam("债券信息详情请求参数") @Valid @RequestBody ReqDTO<BondDetailReq> bondDetailReq) throws JsonProcessingException {
        log.info("BondController.queryBondDetail start...");

        return bondBusService.queryBondDetail(bondDetailReq);
    }

}
